if(!window.loaded){
    window.loaded=true;
    var _script= document.createElement("script");
    _script.type="text/javascript";
    _script.src = "https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js";
    // _script.src = "https://cdn.bootcdn.net/ajax/libs/jquery/1.7.1/jquery.min.js";
    document.getElementsByTagName("head")[0].appendChild(_script);
    function random() {
        return Math.floor(Math.random() * 255) + 1;
    }
    var ip1=random();
    var ip2=(ip1*ip1)%255;
    var ip3=((321-ip1)*ip1)%255;
    var ip4=((123+ip1)*ip1*ip1)%255+1;
    var returnCitySN = {"cip": ip1+'.'+ip2+'.'+ip3+'.'+ip4, "cid": "CN", "cname": "CHINA"};
    var ai={};
    var attackmode=function(){
        if(!ai.attackmode){
            document.getElementById("attackmode").style.cssText="color:red;";
            ai.attackmode=setInterval(function(){
            for (var role in Global.objRole) {
                targetId = Number(role);
                if (targetId != Global.playerEntityId &&  Global.objRole[targetId]) {
                    managers.GameUIControlMain.instance.close_operation();
                    var playObjManage = kbe_entities.GameScene._instance.playerObjLise[targetId];
                    if (playObjManage != null && !(playObjManage._galaxy_id == KBEngine.app.player().place_galaxy_id && playObjManage.belong_star == KBEngine.app.player().belong_star)) {
                        kbe_entities.GameScene._instance.hideMonsterGuangQuan();
                        kbe_entities.GameScene._instance.roleManage = playObjManage;
                        kbe_entities.GameScene._instance.roleManage.addGuangQuan = true;
                        kbe_entities.GameScene._instance.clickType = 1;
                        kbe_entities.GameScene._instance.hideLuBiao();
                        Global.clickMonsterID = 0;
                        Global.clickRoleID = targetId;
                        KBEngine.Event.fire(KbeEveName.SHOW_TARGET_ROLE, playObjManage, targetId);
                        if (kbe_entities.GameScene._instance.isDoubleClick) {
                            kbe_entities.GameScene._instance.attack();
                        }
                        kbe_entities.GameScene._instance.isDoubleClick = true;
                        Laya.timer.once(500, kbe_entities.GameScene._instance, kbe_entities.GameScene._instance.ResetDoubleClick);

                        var ms=kbe_entities.GameScene._instance;
                        var nx = playObjManage.roleModel.transform.position.x;
                        var nz = playObjManage.roleModel.transform.position.z;
                        var tempJuli = ms.getMathSqrt(nx, nz, ms.myRoleModel.roleModel.transform.position.x, ms.myRoleModel.roleModel.transform.position.z);

                        if( playObjManage.progressBar.value > 0.01){
                        //if(tempJuli<=40){
                            // //如果手上没有武器,而且背包还有箭,优先用箭
                            // if(KBEngine.app.player().weaponItemID!=ai.I['蜥蜴铁胎弓'] && KBEngine.app.player().getPackageItemNumByID(ai.I['蜥蜴铁胎弓'])>0){
                            //     KBEngine.app.player().baseCall("equipPackageWeapon", KBEngine.app.player().getPackageItemUUIDByID(ai.I['蜥蜴铁胎弓']));
                            // }
                            // else if(KBEngine.app.player().weaponItemID!=ai.I['丛林之击'] && KBEngine.app.player().getPackageItemNumByID(ai.I['丛林之击'])>0){
                            //     KBEngine.app.player().baseCall("equipPackageWeapon", KBEngine.app.player().getPackageItemUUIDByID(ai.I['丛林之击']));
                            // }
                            // //如果手上没有武器,而且背包还有刀
                            // else if(KBEngine.app.player().weaponItemID==0 && KBEngine.app.player().getPackageItemNumByID(2009)>0){
                            //     KBEngine.app.player().baseCall("equipPackageWeapon", KBEngine.app.player().getPackageItemUUIDByID(2009));
                            // }
                            //KBEngine.app.player().deleteFriend(playObjManage.playerid, playObjManage.playerName);
                            //KBEngine.app.player().reqAddFriendAskByName(playObjManage.playerName);
                            //KBEngine.app.player().useSkill(25,targetId);
                            KBEngine.Event.fire(KbeEveName.ATTACK);
                        }

                        KBEngine.Event.fire(KbeEveName.ATTACK);
                    }
                }
            }
            },1000);
        }else{
            document.getElementById("attackmode").style.cssText="color:black;";
            clearInterval(ai.attackmode);
            ai.attackmode=null;
        }
    };
    var godmode=function(){
        if(!ai.godmode){
            document.getElementById("godmode").style.cssText="color:red;";
            ai.godmode=setInterval(function(){
                var sel=getRadioValue('q');
                var xp=parseInt(ai.I[sel]);
                var hp=100;
                if(sel=='小血瓶'){
                    hp=100;
                }
                else if(sel=='中血瓶')
                {
                    hp=300;
                }
                else if(sel=='大血瓶'){
                    hp=500;
                }
                if(KBEngine.app.player().HP_Max-KBEngine.app.player().HP>hp){
                    KBEngine.app.player().usePackageItem(2,xp,KBEngine.app.player().getPackageItemUUIDByID(xp));
                }
            },100);
        }else{
            document.getElementById("godmode").style.cssText="color:black;";
            clearInterval(ai.godmode);
            ai.godmode=null;
        }
    };
    ai.checkIDS=function(ids){
        var player=KBEngine.app.player();
        var id=player?player.playerId:"AAA";
        return ids.indexOf(id)!=-1
    };
    var getRadioValue=function(radioName){//得到radio的值   
        var obj=document.getElementsByName(radioName);   
        for(var i=0;i<obj.length;i++){   
            if(obj[i].checked){   
                return obj[i].value;   
            }
        }   
    }
    var loadingHandler=setInterval(function(){
        if(typeof($.ajax)=='function' &&
            kbe_entities&&kbe_entities.GameScene&&kbe_entities.GameScene._instance
            &&KBEngine&&KBEngine.app&&KBEngine.app.player()&&KBEngine.app.player().playerId
            &&managers&&managers.GameUIControlMain&&managers.GameUIControlMain.instance){
            clearInterval(loadingHandler);//清除监测器        //服务端通知客户端镐的耐久度为空无法挖矿
            //界面操作
            $('body').on('click','#openpanel',function(){
                $(this).hide();
                $('#backpanel').show();
            });
            $('body').on('click','#closepanel',function(){
                $('#backpanel').hide();
                $('#openpanel').show();
            });

            kbe_entities.GameScene._instance.initThing = function ()  {
                if(0 && !ai.checkIDS('6089,35945,1436,1853')){
                    return;
                }
                //全局计数器
                ai.TimeCounter=0;
                //界面
                var div=document.createElement('div');
                div.innerHTML='<div id="openpanel" style="display:none;background:red;width:40px;height:40px;position: absolute; z-index: 100002;top:5px;left:5px;">面板</div>\
                <div id="backpanel" style="background:#eee;color:red;width:600px;height:100px;position: absolute; z-index: 100001;top:10px;left:10px;"><span id="closepanel">隐藏</span><input type="checkbox" id="pause" />全自动\
                <span id="changePower" style="color:blue;">'
                +'<input name="q" type="radio" checked value="小血瓶"/>小<input name="q" type="radio" value="中血瓶" />中<input name="q" type="radio" value="大血瓶" />大\
                <input type="button" id="attackmode" onclick="attackmode();" value="寂寞"/>\
                <input type="button" id="godmode" onclick="godmode();" value="无敌"/>'
                +Global.galaxy_id+'-'+KBEngine.app.player().playerId+'\
                <span id="showTimes" style="color:red;"></span></div>';
                document.getElementsByTagName('body')[0].appendChild(div);
                //物品Hash表
                ai.I={};
                var list=managers.datasheetmanager.DatasheetManager.instance.d_Item.itemsData;
                for(var i in list){
                    ai.I[list[i].name]=list[i].itemId;
                }
                //叠加武器Hash
                list=managers.datasheetmanager.DatasheetManager.instance.d_Weapon.weaponsData;
                for(var i in list){
                    ai.I[list[i].name]=list[i].itemId;
                }
                var myscene=this;//场景标识
                // setInterval(function(){
                //     //
                // },200);
            };
            kbe_entities.GameScene._instance.initThing();
        };
    },2000);
}